package com.minimalist.lindi.controller;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.tradeapplication.LindiTradeApplicationAgreeVO;
import com.minimalist.common.entity.lindi.vo.tradeapplication.LindiTradeApplicationQueryVO;
import com.minimalist.common.entity.lindi.vo.tradeapplication.LindiTradeApplicationVO;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import com.minimalist.lindi.service.LindiTradeApplicationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_交易申请管理")
@RequestMapping("/lindi/tradeApplication")
public class LindiTradeApplicationController{

    @Autowired
    private LindiTradeApplicationService service;

    @PostMapping("/addTradeApplication")
    @Operation(summary = "添加交易申请")
    public R<?> addTradeApplication(
            @RequestBody @Validated(Add.class)
            LindiTradeApplicationVO tradeApplicationVO){
        service.addTradeApplication(tradeApplicationVO);
        return R.ok();
    }

    @DeleteMapping("/deleteTradeApplicationByTradeApplicationId")
    @Operation(summary = "删除交易申请 -> 根据交易申请ID删除")
    public R<?> deleteTradeApplicationByTradeApplicationId(
            @RequestParam("tradeApplicationId")
            @NotNull(message = "交易申请ID不能为空")
            @Parameter(name = "tradeApplicationId", required = true, description = "交易申请ID")
            Long tradeApplicationId){
        service.deleteTradeApplicationByTradeApplicationId(tradeApplicationId);
        return R.ok();
    }

    @PutMapping("/updateTradeApplicationByTradeApplicationId")
    @Operation(summary = "修改交易申请")
    public R<?> updateTradeApplicationByTradeApplicationId(
            @RequestBody @Validated(Update.class)
            LindiTradeApplicationVO tradeApplicationVO){
        service.updateTradeApplication(tradeApplicationVO);
        return R.ok();
    }

    @GetMapping("/getPageTradeApplicationList")
    @Operation(summary = "查询交易申请列表(分页)")
    public R<PageResp<LindiTradeApplicationVO>> getPageTradeApplicationList(
            @RequestBody LindiTradeApplicationQueryVO queryVO){
        return R.ok(service.getPageTradeApplicationList(queryVO));
    }

    @GetMapping("/getTradeApplicationByTradeApplicationId/{tradeApplicationId}")
    @Operation(summary = "根据交易申请ID查询交易申请")
    public R<LindiTradeApplicationVO> getTradeApplicationByTradeApplicationId(
            @PathVariable(value = "tradeApplicationId")
            @NotNull(message = "交易申请ID不能为空")
            @Parameter(name = "tradeApplicationId", description = "交易申请ID", required = true)
            Long tradeApplicationId){
        return R.ok(service.getTradeApplicationByTradeApplicationId(
                tradeApplicationId));
    }

    @PostMapping("/agreeTradeApplication")
    @Operation(summary = "是否同意交易申请")
    public R<?> agreeTradeApplication(
            @RequestBody @Validated(Update.class)
            LindiTradeApplicationAgreeVO agreeVO){
        service.agreeTradeApplication(agreeVO);
        return R.ok();
    }

    @PostMapping("/approveTradeApplication")
    @Operation(summary = "审批交易申请")
    public R<?> approveTradeApplication(
            @RequestBody @Validated(Update.class)
            LindiTradeApplicationAgreeVO agreeVO){
        service.approveTradeApplication(agreeVO);
        return R.ok();
    }
}